const lodash = require('lodash')
import Base from "../entities/Base"

const HeaderBtnMixin = {
    data() {
        return {
            page: 1,
            status: -1,
            dialogFormVisible: false,
            headerConfig: {
                total: 1,
                showPage: true,
                pageSize: Base.pageSize,
                add: true,
                refresh: true,
                whereDict: {},
                statusBtns: [
                    { status: -1, name: "全部", key: "*" },
                    { status: 0, name: "待采集", key: "status" },
                    { status: 1, name: "已采集", key: "status" },
                    { status: 2, name: "已生成", key: "status" },
                    { status: 3, name: "已发布", key: "status" }
                ]
            }
        }
    },
    methods: {
        getTargets(page) {

        },
        handleAdd() {
            this.dialogFormVisible = true
        },
        handleRefresh() {
            this.getTargets(this.page)
        },
        handleCurrentPage(page) {
            this.page = page
            this.getTargets(page)
        },
        handleStatusFilter(row) {
            this.status = row.status
            this.getTargets(this.page)
        },
        beforeStatusFilter(args) {
            let { data, refs, className } = args
            for (let btn of this.headerConfig.statusBtns) {
                let ref = refs[btn.name][0].$el
                //点击了全部
                if (data.key && data.key == "*") {
                    ref.classList.add(className)
                } else {
                    //处理当前点击的按钮
                    if (data.name == btn.name) {
                        ref.classList.add(className)
                    } else {
                        ref.classList.remove(className)
                    }
                }
            }
            //处理全部按钮
        },
        handleHeaderClick(args) {
            if (!lodash.isUndefined(args.value)) {
                this[args.name](args.value)
            } else {
                this[args.name]()
            }
        },
    }
}

export { HeaderBtnMixin }